
/**
 * 省市的树形
 */
var provinceCityChoose={};

var resetProvinceCityTreeData = function(provinceData,cityData){
	var treeAta = [];
	var provinceIdArray = [];
	$.each(provinceData,function(index,result){
		provinceIdArray.push(result.id);
		treeAta.push({id:result.id,name:result.name,cityArray:[]});
    });
	$.each(cityData,function(index,result){
		var u = provinceIdArray.indexOf(result.province.id);
		if(u>-1){
			treeAta[u].cityArray.push({id:result.id,name:result.name});
		}
    });
	return treeAta;
}

var jstreeProvinceCity = function(treeDiv){
	$('#'+treeDiv).jstree({
	    'core': {
	       'check_callback': true
	    },
	    'plugins': ['types', 'dnd'],
	    'types': {
	        'default': {
	            'icon': 'fa fa-folder'
	        },
	        'city': {
	            'icon': 'fa fa-file-code-o'
	        },
	    }
	}).bind('click.jstree', function(event) {
		var eventNodeName = event.target.nodeName;               
	    if (eventNodeName == 'INS') {                   
	    	return;
	    } else if (eventNodeName == 'A') {                   
	    	var $subject = $(event.target).parent();
	    	var ty = $(event.target).parents('li').attr('title');
	    	provinceCityChoose={};
	    	if(ty=='province'){
	    		provinceCityChoose.province=$(event.target).parents('li').attr('id');
	    	}
	    	else if(ty=='city'){
	    		provinceCityChoose.city=$(event.target).parents('li').attr('id');
	    	}
	    }      
	});
}